﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Araman.Models.UserModels
{
    using Araman.Models;
    using System.Web.Mvc;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using Araman.Resources;
    public class UserStatus
    {
        [Key()]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int StatusId { get; set; }

        [MaxLength(64, ErrorMessageResourceName = "UserStatusName_MaxLength", ErrorMessageResourceType = typeof(LngModelErrors))]
        [Required(AllowEmptyStrings = false, ErrorMessageResourceName = "UserStatusName_Null", ErrorMessageResourceType = typeof(LngModelErrors))]
        [Display(ResourceType = typeof(LngModelDisplayNames), Name = "User_StatusName")]
        public string StatusName { get; set; }


        [Required(AllowEmptyStrings = false, ErrorMessageResourceName = "UserStatusName_LanguageKey_Null", ErrorMessageResourceType = typeof(LngModelErrors))]
        [MaxLength(64, ErrorMessageResourceName = "UserStatusName_LanguageKey_MaxLength", ErrorMessageResourceType = typeof(LngModelErrors))]
        [Display(ResourceType = typeof(LngModelDisplayNames), Name = "User_StatusName_LanguageKey")]
        public string StatusNameLanguageKey { get; set; }


        public virtual IEnumerable<Userr> Users { get; set; }

        public static UserStatus Active { get { return StatusFromName("Active"); } }
        public static UserStatus EmailNotVerified { get { return StatusFromName("EmailNotVerified"); } }
        public static UserStatus Banned { get { return StatusFromName("Banned"); } }
        public static UserStatus Deactivated { get { return StatusFromName("Deactivated"); } }

        public static UserStatus StatusFromId(int statusId)
        {
            if (statusId <= 0)
                return null;

            return (from st in DbModel.Current.UserStatuses where st.StatusId == statusId select st).FirstOrDefault<UserStatus>();
        }
        public static UserStatus StatusFromName(string statusName)
        {
            if (String.IsNullOrEmpty(statusName.Trim()))
                return null;

            return (from st in DbModel.Current.UserStatuses where st.StatusName == statusName select st).FirstOrDefault<UserStatus>();
        }

    }
}